<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('ok');
            }, 1000);
        })
        console.log(0);
        async function fn() {
            console.log(111);
            let res = await p;
            console.log('res: ', res);
            console.log(222);
            console.log(333);
        }

        fn();
        console.log('last end');


        // 相当于如下代码
        console.log(0);
        function fn2() {
            console.log(111);
            p.then(res => {
                console.log('res: ', res);
                console.log(222);
                console.log(333);
            })
        }
        fn2();
        console.log('last end');

    </script>
</body>

</html>